#include <stdafx.h>
#include "BloomShader.h"

int BloomShader::Init(char * fileVertexShader, char * fileFragmentShader)
{
	vertexShader = esLoadShader(GL_VERTEX_SHADER, fileVertexShader);

	if ( vertexShader == 0 )
		return -1;

	fragmentShader = esLoadShader(GL_FRAGMENT_SHADER, fileFragmentShader);

	if ( fragmentShader == 0 )
	{
		glDeleteShader( vertexShader );
		return -2;
	}

	program = esLoadProgram(vertexShader, fragmentShader);

	//finding location of uniforms / attributes
	VertPosition = glGetAttribLocation(program, "a_VertPosition");
	VertTexCoord = glGetAttribLocation(program, "a_VertTexCoord");
	VertNorm = glGetAttribLocation(program, "a_VertNorm");
	WVPMatrix = glGetUniformLocation(program, "u_WVPMatrix");
	WMatrix = glGetUniformLocation(program, "u_WMatrix");
	CameraPosition = glGetUniformLocation(program, "u_CameraPosition");
	LightPosition = glGetUniformLocation(program, "u_LightPosition");
	Limit = glGetUniformLocation(program, "u_Limit");
	Near = glGetUniformLocation(program, "u_near");
	Far = glGetUniformLocation(program, "u_far");
	Fade = glGetUniformLocation(program, "u_fade");
	Clarity = glGetUniformLocation(program, "u_clarity");
	Step = glGetUniformLocation(program, "u_step");

	Texture[0] = glGetUniformLocation(program, "u_Texture1");
	Texture[1] = glGetUniformLocation(program, "u_Texture2");
	Texture[2] = glGetUniformLocation(program, "u_TextureDepth");

	return 0;
}

BloomShader::~BloomShader()
{
	glDeleteProgram(program);
	glDeleteShader(vertexShader);
	glDeleteShader(fragmentShader);
}